package com.dcbeida.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.bean.CardEnum;
import com.dcbeida.bean.MyClientBean;
import com.dcbeida.bean.Patient;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 我的客户
 */
public class PatientListAdapter extends BaseAdapter {

    private ArrayList<Patient> mArrayList = new ArrayList<>();
    private Context mContext;

    public PatientListAdapter(Context context) {
        super();
        this.mContext = context;
    }


    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.my_patient_item, null, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Patient bean = mArrayList.get(position);
        holder.tv_name.setText("患者姓名:"+bean.getTruename());

        holder.tv2.setText("证件号码:" + CardEnum.getCardName(bean.getCardtype()) + "  "+bean.getIdcardnum());
        holder.tv3.setText("医院:"+bean.getHospitalname() );

        if(bean.getIsourshopadd() == 1 ){
            holder.tvAddStatus.setVisibility(View.VISIBLE);
        }else {
            holder.tvAddStatus.setVisibility(View.GONE);
        }

        return convertView;
    }


    public ArrayList<Patient> getmArrayList() {
        return mArrayList;
    }

    public void setmArrayList(ArrayList<Patient> mArrayList) {
        if (mArrayList.size() >= 0) {
            this.mArrayList.addAll(mArrayList);
        }
        notifyDataSetChanged();
    }

    public void clearList() {
        this.mArrayList.clear();
    }


    class ViewHolder {
        @Bind(R.id.tv_name)
        TextView tv_name;
        @Bind(R.id.tv2)
        TextView tv2;
        @Bind(R.id.tv3)
        TextView tv3;
        @Bind(R.id.tv_add_status)
        TextView tvAddStatus;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
